package com.xykj.web.controller;

import com.alibaba.fastjson.JSON;
import com.xykj.common.exception.BusinessException;
import com.xykj.common.response.Response;
import com.xykj.pojo.dto.ChinaIndexDto;
import com.xykj.service.ChinaIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/china-index")
public class ChinaIndexController {
    @Autowired
    private ChinaIndexService chinaIndexService;
    @GetMapping("/getChinaIndex")
    public Response getChinaIndex(@RequestParam Integer pageSize, @RequestParam Integer pageNum){
        if (pageSize == null || pageNum == null){
            throw new BusinessException("页面大小和页号不能为空");
        }
        if (pageSize <=0 || pageNum <=0){
            throw new BusinessException("页面大小和页号不能为负数");
        }
        List<ChinaIndexDto> chinaIndexDtos = chinaIndexService.queryChinaIndex(pageNum, pageSize);
        Integer count=chinaIndexService.totalChinaIndex();
        Map<String,Object> map=new HashMap<>();
        map.put("results",chinaIndexDtos);
        map.put("total",count);
        return Response.success("查询成功",map);
    }
}
